#include <stdio.h>
#include "ofc/DDiscreteDistribution.h"

int main(int argc, char *argv[])
{
  DDiscreteDistribution *dis  = [DDiscreteDistribution new];
  DListIterator         *iter;

  double d;

                                       // Setup the discrete ranges
  for (d = 0.0; d < 5.0; d += 0.5)
  {
    [dis range :d :d+0.5];
  }

                                       // Set the values for the distribution
  if (![dis update :0.1]) printf("Value 0.1 is not valid for the distribution.\n");
  if (![dis update :4.2]) printf("Value 4.2 is not valid for the distribution.\n");
  if (![dis update :3.6]) printf("Value 3.6 is not valid for the distribution.\n");
  if (![dis update :2.2]) printf("Value 2.2 is not valid for the distribution.\n");
  if (![dis update :0.5]) printf("Value 0.5 is not valid for the distribution.\n");
  if (![dis update :3.0]) printf("Value 3.0 is not valid for the distribution.\n");
  if (![dis update :2.1]) printf("Value 2.1 is not valid for the distribution.\n");
  if (![dis update :4.9]) printf("Value 4.9 is not valid for the distribution.\n");

                                       // Calculate some numbers
  printf("Number of values in the distribution:%d.\n", [dis length]);
  printf("Sum    of values in the distribution:%.1f.\n", [dis sum]);
  printf("SqSum  of values in the distribution:%.1f.\n", [dis sumSquared]);
  printf("Mean   of values in the distribution:%.1f.\n", [dis mean]);
  printf("StdDev of values in the distribution:%.1f.\n", [dis standardDeviation]);
  
                                       // Scores iterator
  iter = [dis scores];
  if (iter != nil)
  {
    DScore *sc = [iter first];

    while (sc != nil)
    {
      printf("Score:[%.1f-%0.1f] sum:%.1f sq-sum:%.1f perc:%.1f%%.\n",
             [sc min], [sc max], [sc sum], [sc sumSquared], [sc percentage]);
      sc = [iter next];
    }
  }
  else
    printf("No scores in the distribution ?!\n");

  [iter free];
  [dis  free];                         // Cleanup

  return 0;
}

